import { getUserAvatar } from '@/api/user'

const user = {

  state: {
    avatar: ''
  },
  mutations: {
    setAvatar(state, avatar) {
      state.avatar = avatar
    }
  },
  actions: {
    //用户退出登录
    userLogout( { commit } ) {
      return new Promise(resolve => {
        localStorage.removeItem('Authorization')
        location.reload();
        resolve()
      })
    },
    //获取个人头像
    getAvatar({ commit }) {
      return new Promise(resolve => {
        getUserAvatar().then(res=>{
          let avatar = res.data.data.avatar
          commit('setAvatar', avatar)
          resolve()
        })
      })
    }
  },
  getter: {}

}

export default user
